package com.lighthouse.doc.base.dao;

import com.lighthouse.doc.base.domain.KnowledgeDocBaseInfo;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.*;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

import java.util.List;

/**
 * @author ysz
 */
@Configuration
public interface KnowledgeDocBaseInfoRepository extends ElasticsearchRepository<KnowledgeDocBaseInfo, String> {
    /**
     * 查询所有数据
     * @return
     */
    @Override
    List<KnowledgeDocBaseInfo> findAll();

    /**
     * 查询所有已发布数据
     * @return
     */
    List<KnowledgeDocBaseInfo> findByDocStatus(String docStatus);

    /**
     * 查询所有已发布数据
     * @return
     */
    List<KnowledgeDocBaseInfo> findByDocStatus(String docStatus, Pageable pageable);

    /**
     * 根据ID查询指定文档
     * @return
     */
    List<KnowledgeDocBaseInfo> findByDocStatusAndDocIdIn(String docStatus, List<String> docIds);

    /**
     * 根据ID删除文档
     * @return
     */
    int deleteByDocIdIn(List<String> docIds);

    /**
     * 查询我的发布
     * @return
     */
    List<KnowledgeDocBaseInfo> findByDocStatusAndCreateUser(String docStatus, Long owner);

    /**
     * 查询本目录下所有数据
     * @return
     */
    List<KnowledgeDocBaseInfo> findByRepoId(String repoId);

    /**
     * 根据文档名称或内容进行检索
     * @param docName
     * @param docContentText
     * @return
     */
    @Highlight(
            fields = {
                    @HighlightField(name = "docName"),
                    @HighlightField(name = "docContentText")
            },
            parameters = @HighlightParameters(
                    preTags = "<strong><font style='color:#d80000'>",
                    postTags = "</font></strong>",
                    fragmentSize = 500,
                    numberOfFragments = 3
            )
    )
    List<SearchHit<KnowledgeDocBaseInfo>> findByDocNameOrDocContentText(String docName, String docContentText);

    /**
     * 根据tag查询doc
     * @return
     */
    List<KnowledgeDocBaseInfo> findByDocStatusAndDocTagsIn(String docStatus, List<Long> docTags);

    /**
     * 根据tag查询doc，且docid不在范围
     * @return
     */
    List<KnowledgeDocBaseInfo> findByDocStatusAndDocTagsInAndDocIdNotIn(String docStatus, List<Long> docTags, List<String> docIds);
}
